<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" href="../lib/layui/css/layui.css" />
		<script type="text/javascript" src="../js/global.js"></script>
		<script type="text/javascript" src="../lib/layui/layui.js"></script>
	</head>

<body>
	<div class="x-nav">
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
		<!--多条件-->
		<div class="layui-form-item" style="margin-top: 10px; margin-left:10px">
			<form class="layui-form" method="post" onsubmit="return false;">
				<label class="layui-form-mid">姓名:</label>
				<div class="layui-input-inline" style="width:100px;">
					<input type="text" id="name" name="name" autocomplete="off" class="layui-input">
				</div>
				<!--<label class="layui-form-mid">电话:</label>
				<div class="layui-input-inline" style="width:150px;">
					<input type="text" name="phone" id="phone" autocomplete="off" class="layui-input">
				</div>-->
				<!--<label class="layui-form-mid">咨询师:</label>
				<div class="layui-input-inline" style="width:150px;">
					<input type="text" name="askername" id="askername" autocomplete="off" class="layui-input">
				</div>-->
				<!--<label class="layui-form-mid">是否缴费:</label>
				<div class="layui-input-inline" style="width:150px;">
					<input type="text" name="ispay" id="ispay" autocomplete="off" class="layui-input">
				</div>-->
				<label class="layui-form-mid">创建时间:</label>
				<div class="layui-input-inline" style="width:150px;">
					<input type="text" name="begin" id="begin" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">--</label>
				<div class="layui-input-inline" style="width:150px;">
					<input type="text" name="end" id="end" autocomplete="off" class="layui-input">
				</div>
				<!--<label class="layui-form-mid">是否回访:</label>
				<div class="layui-input-inline" style="width:150px;">
					<input type="text" name="ishome" id="ishome" autocomplete="off" class="layui-input">
				</div>
-->
				<div class="layui-input-inline" style="width:100px;">
					<button class="layui-btn" id="search" data-type="reload">搜索</button>
				</div>
			</form>
		</div>
		<!--添加-->
		<div id="addDiv" class="layui-form-item" style="margin-top: 10px; margin-left:10px;display: none;">
			<form id="addForm" lay-filter="addForm" class="layui-form" method="post" onsubmit="return false;">
				<div class="layui-form-item">
					<label class="layui-form-mid">姓名：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="name" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">年龄：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="age" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">性别：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<select name="sex" lay-verify="required">
				          <option value="">-请选择-</option>
				          <option value="男">男</option>
				          <option value="女">女</option>
				        </select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">电话：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="phone" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">学历：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="stuxueli" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">QQ：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="qq" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">微信：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="weixin" lay-verify="required" />
					</div>
				</div>
<div class="layui-form-item">
							<label class="layui-form-mid">现居住地：</label>
							<div class="layui-input-inline"style="width: 350px;">
								<input type="text" id="address" name="address" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-mid">来源方式：</label>
							<div class="layui-input-inline"style="width: 350px;">
								<input type="text" id="msgsource" name="msgsource" id="date" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
				<div class="layui-form-item" style="text-align: center;">
					<button id="addBtn" class="layui-btn" lay-filter="test" lay-submit>添加</button>
				</div>
			</form>
		</div>
		<!--修改-->
		<div id="updateDiv" class="layui-form-item" style="margin-top: 10px; margin-left:10px;display: none;">
			<form id="updateForm" lay-filter="updateForm" class="layui-form" method="post" onsubmit="return false;">
				<div class="layui-form-item">
					<label class="layui-form-mid">姓名：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="name" lay-verify="required|vname" />
						<input class="layui-input" type="hidden" name="id" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">年龄：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="age" lay-verify="required|number" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">性别：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<select name="sex" lay-verify="required">
				          <option value="男">男</option>
				          <option value="女">女</option>
				        </select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">电话：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="phone" lay-verify="required|phone" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">学历：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="stuxueli" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">QQ：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="qq" lay-verify="required|number" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">微信：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="weixin" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
							<label class="layui-form-mid">现居住地：</label>
							<div class="layui-input-inline"style="width: 350px;">
								<input type="text" id="address" name="address" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-mid">来源方式：</label>
							<div class="layui-input-inline"style="width: 350px;">
								<input type="text" id="msgsource" name="msgsource" id="date" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
				<!--<div class="layui-form-item">
					<label class="layui-form-mid">是否缴费：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="ispay" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">是否回访：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="ishome" lay-verify="required" />
					</div>
				</div>-->
				<!--<div class="layui-form-item">
					<label class="layui-form-mid">创建时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" name="createtime" lay-verify="required" />
					</div>
				</div>-->
				<div class="layui-form-item" style="text-align: center;">
					<button id="updateBtn" class="layui-btn" lay-filter="test1" lay-submit>修改</button>
				</div>
			</form>
		</div>
			
			
			
			
		<!--详情-->
		<div id="xqDiv" class="layui-form-item" style="margin-top: 10px; margin-left:10px;display: none;">
			<form id="xqForm" lay-filter="xqForm" class="layui-form" method="post" onsubmit="return false;">
				<div class="layui-form-item">
					<label class="layui-form-mid">客户姓名：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="name" lay-verify="required" />
						<input class="layui-input" type="hidden" name="id" lay-verify="required" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">年龄：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="age" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">性别：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="sex" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">电话：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="phone" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">学历：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="stuxueli" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">透视：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="perstate" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">来源：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="msgsource" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">来源关键字：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="sourcekeyword" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">地址：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="address" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">网推：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="netpusherid" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">咨询师：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled id="didi" name="askername" lay-verify="required|vname" />
						
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">QQ：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="qq" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">微信：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="weixin" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">内容：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="content" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">课程方向：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="learnforword" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否有效：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="isvalid" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">记录：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="rercord" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否退回：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="isreturnvist" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">第一次访问时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="firstvisittime" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否家访：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="ishome" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">家访时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="hometime" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">最后的有效期：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="lostvalid" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">是否缴费：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="ispay" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">缴费时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="paytime" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">钱数：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="money" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否退钱：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="isreturnmoney" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否上课：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="isinclass" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">上课时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="inclasstime" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">课堂内容：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="inclasscontent" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">咨询内容：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="askercontent" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否删除：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="isdel" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">客户音乐：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="stuconcert" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">是否报备：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="isbaobei" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">退钱原因：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="returnmoneyreason" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">预付学费：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="premoney" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">预付时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="premoneytime" lay-verify="required|vname" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-mid">创建时间：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="createtime" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">创建用户：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="createuser" lay-verify="required|vname" />
					</div>
				</div>
					<div class="layui-form-item">
					<label class="layui-form-mid">状态：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<input class="layui-input" disabled name="stustate" lay-verify="required|vname" />
					</div>
				</div>
					
			</form>
		</div>

		<!--批量修改-->
		<div id="updateAllDiv" class="layui-form-item" style="margin-top: 10px; margin-left:10px;display: none;">
			<form id="updateAllForm" lay-filter="updateAllForm" class="layui-form" method="post" onsubmit="return false;">

				<div class="layui-form-item">
					<label class="layui-form-mid">咨询师：</label>
					<div class="layui-input-inline" style="width: 350px;">
						<select id="did3" lay-verify="required">
							<option value="">请选择</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item" style="text-align: center;">
					<button id="updateAllBtn" class="layui-btn" lay-filter="test2" lay-submit>修改</button>
				</div>
			</form>
		</div>
		<!--头部按钮-->
		<script type="text/html" id="top">
			<button class="layui-btn" type="button" lay-event="add">添加</button>
			<button class="layui-btn" lay-event="updateAll">批量修改</button>
			<button class="layui-btn" lay-event="excelAll">导出excel</button>
			<button class="layui-btn" lay-event="msg">发送消息</button>
						<button type="button" class="layui-btn" id="ab">
  	<i class="layui-icon">&#xe67c;</i>上传文件
  </button>
		</script>

		<!-- 行内工具栏 -->
		<script type="text/html" id="line">
			
			<button class="layui-btn layui-btn-sm" type="button" lay-event="update">编辑</button>
			<button class="layui-btn layui-btn-sm" type="button" lay-event="del">删除</button>
			<button class="layui-btn layui-btn-sm" type="button" lay-event="mes">消息</button>
		</script>

		<!--数据表格-->
		<table id="demo" lay-filter="demo"></table>
		<script>
			layui.use(['layer', 'table', 'form', 'laydate','excel','upload'], function() {
				var table = layui.table;
				var $ = layui.$;
				var form = layui.form;
				var layer = layui.layer;
				var laydate = layui.laydate;
				var excel = layui.excel;
				var upload=layui.upload;
				var arr = []; //批量修改集合
				var zdfpzxs=localStorage.value;

				laydate.render({
					elem: '#begin',
					format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
				});
				laydate.render({
					elem: '#end',
					format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
				});

				table.render({
					elem: "#demo",
					url: "http://localhost:8080/stu/findAll",
					method: "post",
					page: true,
					where: {
						"uname": globalData.getCurUName(),
						"token": globalData.getCurToken()
					},
					toolbar: "#top",
					parseData: function(res) {
						return {
							"code": 0,
							"msg": "",
							"count": res.totalElements,
							"data": res.content
						}
					},
					cols: [
						[{
								type: 'checkbox'
							},
							{
								field: 'id',
								title: '编号'
							},
							{
								field: 'name',
								title: '姓名'
							},
							{
								field: 'age',
								title: '年龄'
							},
							{
								field: 'sex',
								title: '性别'
							},
							{
								field: 'phone',
								title: '电话'
							},
							{
								field: 'stuxueli',
								title: '学历'
							},
							{
								field: 'qq',
								title: 'QQ'
							},
							{
								field: 'weixin',
								title: '微信'
							},
							{
								title: '咨询师姓名',
								//templet: "<div>{{d.asker.askername}}<div>",
								templet:
						function(d){
							if(d.asker!=null){
								return d.asker.askername;
							}
							else{
								return '<span style="color: red;">未分配咨询师</span>';
							}
						}
							},
							
							/*{
								field: "ispay",
								title: '是否缴费',
							},*/
							{
								field: "createtime",
								title: '创建时间'
							},
							/*{
								field: "ishome",
								title: '是否回访',
							},*/
							/*{
								templet: "<div>{{d.asker.rolename}}<div>",
								title: '职位名称',
							},*/
							{
								title: '操作',
								toolbar: "#line",
								width:"20%"
							},
						]
					],
					id: "demoid"
				})

				/*导入*/
		    upload.render({
			elem:'#ab',
			url:'http://localhost:8080/stu/Excel?token='+globalData.getCurToken()+"&zdfpzxs="+zdfpzxs,
			accept:'file',
			multiple:true,
			done:function(res){
                console.log(res.errorlist);
                    if(res.errorCount == 0) {
	                     layer.msg("共" + res.successCount + "条数据，导入成功");
	                     active.reload();
                    }else {
	                     layer.confirm("导入成功" + res.successCount + "条，<br/>导入失败" + res.errorCount + "条!<br/>是否导出错误信息", function(index) {
		                 layer.close(index);
		                 var data = res.errorlist;
		        //需要导入的字段
		        data = excel.filterExportData(data, [
			         "id", "name", "sex", "age", "phone", "stuxueli", "qq", "weixin"
		        ]);
		        data.unshift({
		        	id:"编号",
			        name: "姓名",
			        sex: "性别",
			        age: "年龄",
			        phone: "电话",
			        stuxueli: "学历",
			        qq: "QQ",
			        weixin: "微信"
		        });
		        excel.exportExcel(data, 'stuRu.xlsx', 'xlsx');
		                layer.msg("错误信息导出成功");
	            }, function(index, item) {
		                location.reload();
	              })
                }
              },
                error: function() {
                        layer.alert("请检查excel格式是否正确");
                 }
                
              })

				active = {
					reload: function() {
						table.reload("demoid", {
							where: {
								"name": $("#name").val(),
								"phone": $("#phone").val(),
								"askername": $("#askername").val(),
								"ispay": $("#ispay").val(),
								"begin": $("#begin").val(),
								"end": $("#end").val(),
								"ishome": $("#ishome").val(),
								"token": globalData.getCurToken()
							}

						})
					}
				}
				$("#search").on("click", function() {
					active.reload();
				});
					
				$(function() {
					$.post("http://localhost:8080/findAllAsker", {"token":globalData.getCurToken()}, function(res) {
						var d = "";
						for(var i = 0; i < res.length; i++) {
							d += "<option value=" + res[i].askerid + ">" + res[i].askername + "</option>";
						}
						$("#did").append(d);
						$("#did1").append(d);
						$("#did2").append(d);
						$("#did3").append(d);
						form.render('select');
					}, "json")

				})
				var zxs=null;
				/* 顶部工具栏监听 */
				table.on('toolbar(demo)', function(obj) {
					if(obj.event == "add") {
						layer.open({
							type: 1,
							title: "添加",
							content: $("#addDiv"),
							area: ['500px', '600px']
						})
					} else if(obj.event == "updateAll") {
						var data = table.checkStatus("demoid").data;
						if(data.length < 1) {
							layer.msg("未选择修改数据");
						} else {
							for(var i = 0; i < data.length; i++) {
								arr.push(data[i].id);
							}
							layer.open({
								type: 1,
								title: "批量修改",
								content: $("#updateAllDiv"),
								area: ['500px', '600px']
							})
						}
					}
					/*导出*/
				if(obj.event == "excelAll") {
					//testReload是table.render(渲染)的id
					var data = table.checkStatus("demoid").data;
					if(data.length < 1) {
						layer.msg("未选择导出客户");
					} else {
							var dlform = document.createElement('form');
              dlform.style = "display:none;";
              dlform.method = 'post';
              dlform.action = globalData.server+"stu/stuExcelOut";
              var hdnFilePath = document.createElement('input');
              hdnFilePath.type = 'hidden';
              hdnFilePath.name = 'token';
              hdnFilePath.value = globalData.getCurToken();
              var da = document.createElement('input');
              da.type = 'hidden';
              da.name = 'data';
              da.value =JSON.stringify(data);
              dlform.appendChild(hdnFilePath);
              dlform.appendChild(da);
              document.body.appendChild(dlform);
              dlform.submit();
              document.body.removeChild(dlform);
          }
				}
				
				if(obj.event == "msg") {
						var data = table.checkStatus("demoid").data;
						if(data.length < 1) {
							layer.msg("请选择客户");
						} else {
							for(var i = 0; i < data.length; i++) {
								arr.push(data[i].id);
							}
							  layer.prompt({title: '动态消息', formType: 2}, function(text, index){
							    $.post(globalData.server+"/msg/saveMessage",{
							    	"token":globalData.getCurToken(),
							    	"ids":arr.join(),
							    	"userid":globalData.getCurUid(),
							    	"status":"未读",
							    	"msg":text,
							    	"time":dateFtt("yyyy-MM-dd hh:mm:ss",new Date())
							    },function(res){
							    	if(res=arr.length){
							    		layer.close(index);
							    		layer.msg("该信息已成功发送");
							    		arr = [];
							    		active.reload();
							    		
							    	}else{
							    		layer.msg("该信息未发送成功");
							    	}
							    })
							  });
						}
					}
				})
				
				var stuid;
				/* 行内工具监听 */
				table.on("tool(demo)", function(obj) {
					//修改
					if(obj.event == "update") {
						$("#did2").val(obj.data.asker.askerid);
						form.val("updateForm", obj.data);
						layer.open({
							type: 1,
							title: '修改',
							content: $("#updateDiv"),
							area: ['550px', '600px']
						})
					}
					if(obj.event == "del") {
						layer.confirm('确定删除吗？',function(){
							$.post(globalData.server+"/stu/del",{
								'token':globalData.getCurToken(),
								'id':obj.data.id
							},function(res){
								if(res>0){
									layer.msg("删除成功");
									active.reload();
								}else{
									layer.msg("该用户有咨询师正在跟进无法删除哦");
								}
							},"json");
						})
					}
					if(obj.event == "mes") {
						zxs=obj.data.asker.askername;
						stuid=obj.data.id;
						
						 layer.prompt({title: '动态消息', formType: 2}, function(text, index){
							    $.post(globalData.server+"/msg/addMsg",{
							    	"token":globalData.getCurToken(),
							    	"stuid":stuid,
							    	"askerid":zxs,
							    	"userid":globalData.getCurUid(),
							    	"status":"未读",
							    	"msg":text,
							    	"time":dateFtt("yyyy-MM-dd hh:mm:ss",new Date())
							    },function(res){
							    	if(res>0){
							    		layer.closeAll();
							    		layer.msg("该信息已成功发送");
							    		/*点击添加按钮向服务器发送消息,服务器根据zxs发送实时消息*/
							    		var ws = parent.ws;
										ws.send(zxs);
							    		active.reload();
							    	}else if(res.code=-1){
							layer.msg(res.msg);
						}else{
							    		layer.msg("该信息未发送成功");
							    	}
							    })
							  });
							    
						}
				});
				//监听行单击事件（双击事件为：rowDouble）
			  table.on('rowDouble(demo)', function(obj){
			    
			   $("#didi").val(obj.data.asker.askername);
						form.val("xqForm", obj.data);
						layer.open({
							type: 1,
							title: '详情信息',
							content: $("#xqDiv"),
							area: ['550px', '600px']
						})
			    
			    //标注选中样式
			    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
			  });
				
				form.on('submit(test)', function() {
					var data = $("#addForm").serialize() + "&token=" + globalData.getCurToken()+"&createtime="+dateFtt("yyyy-MM-dd hh:mm:ss",new Date())+"&createuser="+globalData.getCurUName()+"&zdfpzxs="+zdfpzxs;
					$.post('http://localhost:8080/stu/save', data, function(res) {
						if(res > 0) {
							layer.closeAll();
							layer.msg("添加成功！");
							active.reload();
						}else if(res.code=-1){
							layer.msg(res.msg);
						}
					}, "json")
				})
				form.on('submit(test1)', function() {
					var a = $("#updateForm").serialize() + "&token=" + globalData.getCurToken();
					$.post('http://localhost:8080/stu/saveUpStu', a, function(res) {
						if(res > 0) {
							layer.closeAll();
							layer.msg("修改成功！");
							active.reload();
						}else if(res.code=-1){
							layer.msg(res.msg);
						}
					}, "json")
				})
				form.on('submit(test2)', function() {
					var did = $("#did3").val();
					$.post('http://localhost:8080/stu/saveAll', {
						"askerid": did,
						"ids": arr.join(),
						'token': globalData.getCurToken()
					}, function(res) {
						if(res > 0) {
							layer.closeAll();
							layer.msg("修改成功！");
							arr = [];
							active.reload();
						}else if(res.code=-1){
							layer.msg(res.msg);
						}
					}, "json")
				})

//格式化时间
				function dateFtt(fmt, date) { //author: meizz 
					var o = {
						"M+": date.getMonth() + 1, //月份 
						"d+": date.getDate(), //日 
						"h+": date.getHours(), //小时 
						"m+": date.getMinutes(), //分 
						"s+": date.getSeconds(), //秒 
						"q+": Math.floor((date.getMonth() + 3) / 3), //季度 
						"S": date.getMilliseconds() //毫秒 
					};
					if(/(y+)/.test(fmt))
						fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
					for(var k in o)
						if(new RegExp("(" + k + ")").test(fmt))
							fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
					return fmt;
				}
				
			
				
		/*获取url参数*/
										function getQueryVariable(variable){
									       	var query = window.location.search.substring(1);
									       	var vars = query.split("&");
									       	for (var i=0;i<vars.length;i++) {
									            var pair = vars[i].split("=");
									            if(pair[0] == variable){return pair[1];}
									       	}
									       return(null);
										}		
				
				
        })
			
			
		</script>
	</body>

</html>